import React, { FC,ReactElement} from 'react'
import {Navigate} from 'react-router-dom'



// 1- any
/* export default function Index(props: any) {
    //可以通过localStorage.getItem('token)判断是否登录
    // if (localStorage.getItem('token')) {
    //     return props.children;
    // }
    // return ( 
    //         <Navigate to={'/login'}/>
    // )
    return localStorage.getItem('token')?props.children:<Navigate to={'/login'}/>
}
 */

// 2- type指定类型
/* type TProps = {
    children:ReactElement
}

export default function Index(props:TProps) {

    return localStorage.getItem('token')?props.children:<Navigate to={'/login'}/>
  
} */

// 3- 赋值
/* type TProps = {
    children:ReactElement
}

const AuthComponent: FC<TProps> = props => localStorage.getItem('token') ? props.children : <Navigate to={'/login'} />
export default AuthComponent; */

// 4- 赋值 any
const AuthComponent: FC<any> = props => localStorage.getItem('token') ? props.children : <Navigate to={'/login'} />
export default AuthComponent;